package com.lc.user.express.utils;

import com.google.gson.Gson;

/**
 * Created by Administrator on 2016/6/29.
 *
 */
public class GsonUtil {
    private Gson gson = new Gson();

    /**
     *
     * @param src 传入数据
     * @return
     */

    public String toJson(Object src) {
        return gson.toJson(src);
    }

    /**
     *
     * @param json  string类型的字符串和需要写入的类
     * @param claxx
     * @param <T>
     * @return
     */
    public <T> T toObject(String json, Class<T> claxx) {
        return gson.fromJson(json, claxx);
    }

    /**
     *
     * @param bytes 字节数组
     * @param claxx 类
     * @param <T> 泛型
     * @return
     */
    public <T> T toObject(byte[] bytes, Class<T> claxx) {
        return gson.fromJson(new String(bytes), claxx);
    }
}
